package com.wl.mr.join;

import com.wl.mr.wc.WordCountCombiner;
import com.wl.mr.wc.WordCountDriver;
import com.wl.mr.wc.WordCountMapper;
import com.wl.mr.wc.WordCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class DeliveDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        /*
        1. 获取配置文件，获取job实例
        2. 指定程序jar的路径
        3. 指定Mapper、Reducer的类
        4. 指定Mapper输出的KV类型
        5. 指定Reducer输出的KV类型
        6. 指定job处理的数据路径
        7. 指定job输出的数据路径
        8. 提交作业
         */

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "WordCountDriver");

        job.setJarByClass(DeliveDriver.class);

        job.setMapperClass(DeliveMapper.class);
        job.setReducerClass(DeliveReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(DeliveBean.class);

        job.setOutputKeyClass(DeliveBean.class);
        job.setOutputValueClass(NullWritable.class);

        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean flag = job.waitForCompletion(true);

        System.exit(flag?0 : 1);

    }
}
